#include "chatserver.hpp"
#include "ChatService.hpp"
#include <signal.h>
#include <iostream>
#include <hiredis/hiredis.h>
using namespace std;
int main(int argc, char* argv[])
{
  if (argc < 2) {
    cout << "please input port" << endl;
    return 0;
  }
  short port = atoi(argv[1]);
  // 服务器异常中断，关闭所有的客户端连接
  signal(SIGINT, [](int sig)->void {
    LOG_INFO << "server interrupted";
    ChatService::Instance()->Reset();
    exit(0);
  });
  LOG_INFO << "pid = " << getpid();
  muduo::net::EventLoop loop;
  muduo::net::InetAddress listenAddr(port);
  ChartServer server(&loop, listenAddr);
  server.Start();
  loop.loop();
}